package net.akkz.action.imgView;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.akkz.beanFactory.BeanFactory;
import net.akkz.model.Student;
import net.akkz.server.ImgViewServer;

@WebServlet(name="ImgViewGood", urlPatterns="/student/imgViewGood.do")
public class ImgViewGood extends HttpServlet
{
	private ImgViewServer imgViewServer;
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException
	{
		int imgViewId = Integer.parseInt(request.getParameter("imgViewId"));

		Student student = (Student)request.getSession().getAttribute("student");
		if(student == null)
		{
			request.setAttribute("state", "unlogin");
			request.getRequestDispatcher("/jsp/state.jsp").forward(request, response);
			
			return;
		}
		
		int studentId = student.getId();
		
		imgViewServer.addImgViewGood(imgViewId, studentId);
		
		request.setAttribute("state", "success");
		request.getRequestDispatcher("/jsp/state.jsp").forward(request, response);
	}
	
	@Override
	public void init()
	{
		BeanFactory  bf = (BeanFactory) this.getServletContext().getAttribute("beanFactory");
		
		imgViewServer = bf.getBean("imgViewServer");
	}
}
